<template>
	<div>
		<!-- :visible.sync="$store.state.bbsInfoflag" -->
		<el-dialog :close-on-click-modal="flag" :show-close="flag" title="员工信息" :visible.sync="$store.state.staffInfoflag"
		 width="30%" center>
			<span>
				<!-- ////////////////////// -->
				<el-form ref="form" label-width="80px">
					<el-form-item label="员工姓名">
						<el-input v-model="empInfo.empname" maxlength=15></el-input>
					</el-form-item>
					<el-form-item label="员工状态">
						<el-radio v-model="empInfo.empstate" :label="lab0">休假</el-radio>
						<el-radio v-model="empInfo.empstate" :label="lab1">忙碌</el-radio>
						<el-radio v-model="empInfo.empstate" :label="lab2">就绪</el-radio>
					</el-form-item>

					<el-form-item label="员工身份">
						<el-select v-model="empInfo.emptype" placeholder="请选择">
							<el-option :label="item" v-for="(item,i) in emptype" :key="i" :value="item"></el-option>
						</el-select>
					</el-form-item>
				</el-form>
				<!-- ////////////////////// -->
			</span>
			<span slot="footer" class="dialog-footer">
				<el-button type="danger" @click="Staffflag1(false)">删除</el-button>
				<el-button @click="cancel()">取 消</el-button>
				<el-button type="primary" @click="Staffflag(false)">保存</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		request
	} from "network/request.js"
	export default {
		props: {
			empInfo: {
				"empid": 0,
				"empname": "string",
				"empremark": "string",
				"empstate": "string",
				"emptype": [],
			}
		},
		data() {
			return {
				lab0: '0',
				lab1: '1',
				lab2: '2',
				flag: false,
				flag2: true,
				bbstate2: "1",
				emptype: ""
			};
		},
		methods: {
			Staffflag(flag) {
				request({
					url: '/Meal/majorMeals',
					method: 'get',
				}).then(res => {
					if (this.empInfo.emptype == "长期服务") {
						this.empInfo.emptype = "A"
					} else if (this.empInfo.emptype == "短期服务") {
						this.empInfo.emptype = "B"
					} else {
						res.data.forEach(s => {
							if (s.majormealremark == this.empInfo.emptype) {
								this.empInfo.emptype = s.majormealid
							}
						})
					}

					request({
						url: '/Emp/empInfo',
						method: 'patch',
						params: {
							// id:this.$store.state.mealid
							"empid": this.empInfo.empid,
							"empname": this.empInfo.empname,
							"empremark": this.empInfo.empremark,
							"empstate": this.empInfo.empstate,
							"emptype": this.empInfo.emptype
						}
					}).then(res => {
						this.$store.commit("updateStaffInfoflag", false)
						this.$router.push("blank_emt")
					})
				})

			},
			Staffflag1() {
				/*提醒用户是否删除*/
				this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					/*****************/
					request({
						url: '/Meal/majorMeals',
						method: 'get',
					}).then(res => {
						if (res.data.emptype == "长期服务") {
							res.data.emptype = "A"
						} else if (res.data.emptype == "短期服务") {
							res.data.emptype = "B"
						} else {
							res.data.forEach(s => {
								if (s.majormealremark == this.empInfo.emptype) {
									this.empInfo.emptype = s.majormealid
								}
							})
						}
						request({
							url: '/Emp/empInfo',
							method: 'patch',
							params: {
								// id:this.$store.state.mealid
								"empid": this.empInfo.empid,
								"empname": this.empInfo.empname,
								"empremark": this.empInfo.empremark,
								"empstate": this.empInfo.empstate,
								"emptype": this.empInfo.emptype
							}
						}).then(res => {
							this.$store.commit("updateStaffInfoflag", false)
							this.$router.push("blank_emt")
						})
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
			},
			// mealflag1(flag) {
			// 	/*提醒用户是否删除*/
			// 	this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
			// 		confirmButtonText: '确定',
			// 		cancelButtonText: '取消',
			// 		type: 'warning'
			// 	}).then(() => {
			// 		/*****************/
			// 		if (this.bbsInfo.bbsstage == true) {
			// 			this.bbstate2 = "1";
			// 		} else {
			// 			this.bbstate2 = "0"
			// 		}
			// 		request({
			// 			url: '/BbsInfo/Bbsinfo',
			// 			method: 'patch',
			// 			data: {
			// 				// id:this.$store.state.mealid
			// 				"bbsid": this.bbsInfo.bbsid,
			// 				"bbsremark": this.bbsInfo.bbsremark,
			// 				"bbsstage": 2,
			// 				"bbstime": this.bbsInfo.bbstime,
			// 				"bbstype": this.bbsInfo.bbstype,
			// 				"uid": this.bbsInfo.uid
			// 			}
			// 		}).then(res => {
			// 			this.$store.commit("updateBbsInfoflag", false)
			// 			this.$router.push("blank_emt")
			// 			this.$router.push("blank_emt")
			// 		})

			// 		/*****************/
			// 		this.$message({
			// 			type: 'success',
			// 			message: '删除成功!'
			// 		});
			// 	}).catch(() => {
			// 		this.$message({
			// 			type: 'info',
			// 			message: '已取消删除'
			// 		});
			// 	});



			/*************************/

			// },
			cancel() {
				this.$store.commit("updateStaffInfoflag", false)
				// this.$store.commit("updateMealid", 0)
			},
			onSubmit() {
				console.log('submit!');
			}
		},
		created() {
			let emptypes = ["长期服务", "短期服务"];
			request({
				url: '/Meal/majorMeals',
				method: 'get',
			}).then(res1 => {
				res1.data.forEach(s => {
					emptypes.push(s.majormealremark)
				})
				this.emptype = emptypes
			})

		}
	};
</script>

<style scoped>
	.el-select {
		width: 130px;
	}

	.input-with-select .el-input-group__prepend {
		background-color: #fff;
	}
</style>
